from . import data_statistics_bp
from . import Data_Statistics as ds
from flask import request
from flask import jsonify

dataframe = ds.df


@data_statistics_bp.route('/value_count/<field>/<area>/')
def value_count(field, area):
    if area == 'all':
        area = None
    data = ds.value_count_statistics(dataframe, field, area)

    # print(type(data))
    # data_dic = data.to_dict('records')
    # print(data_dic)
    return jsonify(data)


@data_statistics_bp.route('/value_sort/<field>/<area>/')
def value_sort(field, area):
    if area == 'all':
        area = None
    data = ds.value_sort_statistics(dataframe, field, area)

    return jsonify(data)


@data_statistics_bp.route('/mean_area_value/')
def mean_area_value():
    data = ds.area_price_order(dataframe)
    return jsonify(data)


@data_statistics_bp.route('/word_freq/')
def word_freq():
    res_list = ds.title_statistic()
    return jsonify(res_list)
